<?php

	$__sqlprofile=null;
	class SqlProfile{
		
		var $_querys;
		var $_errors;
		var $instance;
		var $index=0;
		
		function SqlProfile(){
			$this->_querys=array();
			$this->_errors=array();
		}
		
		function GetInstance(){
			global $__sqlprofile;
			return $__sqlprofile;
		}
		
		function capture($sql,$tableclass){
			$this->_querys[$this->index++]=array("query"=>$sql,"tableclass"=>$tableclass);
		}
		
		function error($tableclass){
			$this->_errors[$this->index++]=array("error"=>mysql_error(),"tableclass"=>$tableclass);
		}
		
		function Dump(){
			global $__sqlprofile;
			$result="";
			/*foreach($__sqlprofile->_querys as $query){
				$result.= $query["query"]."\n";
			}
			
			foreach($__sqlprofile->_errors as $error){
				$result.= $error["error"]."\n";
			}*/
			foreach(range(0,count($__sqlprofile->_errors)+count($__sqlprofile->_querys)) as $i){
				if(isset($__sqlprofile->_querys[$i])){
					$result.= $__sqlprofile->_querys[$i]["query"]."\n";
				}
				if(isset($__sqlprofile->_errors[$i])){
					$result.= $__sqlprofile->_errors[$i]["error"]."\n";
				}
			}
			return $result;
		}
		
		function GetErrors($tableclass){
			$errors=array();
			foreach($this->_errors as $error){
				if($error["tableclass"]==$tableclass){
					$errors[]=$error["error"];
				}
			}
			return implode("\n",$errors);
		}
		
	}
	
	$__sqlprofile = new SqlProfile();
	
?>